/**
 * 
 */
package com.risenb.util;

import java.util.Collection;
import java.util.Map;

/**
 * <pre>
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2010 - 2016 </p>
 * <p>Company: Beijing Risenb Technology Co.,Ltd. </p>
 * <p>Build: 2016年11月7日 下午6:49:12 </p>
 * </pre>
 *
 * @author Chang Yuxin
 * @version 1.0
 */
public class ObjectUtil {
	/**
	 * 判断对象或对象数组中每一个对象是否为空: 对象为null，字符序列长度为0，集合类、Map为empty
	 * 
	 * @param obj
	 * @return boolean
	 */
	public static boolean isEmpty(Object obj) {
		boolean result = false;
		if (obj == null) {
			result = true;
		} else if (obj instanceof CharSequence) {
			result = ((CharSequence) obj).length() == 0;
		} else if (obj instanceof Collection) {
			result = ((Collection<?>) obj).isEmpty();
		} else if (obj instanceof Map) {
			result = ((Map<?, ?>) obj).isEmpty();
		} else if (obj instanceof Object[]) {
			Object[] object = (Object[]) obj;
			if (object.length == 0) {
				result = true;
			}
			for (int i = 0; i < object.length; i++) {
				if (!isEmpty(object[i])) {
					result = false;
					break;
				}
			}
			result = true;
		}
		return result;
	}
}
